import api from "@/api/index.js"

export default async function acticleFavoritedAction({request, params}) {
    const {method} = request;
    console.log(method)
    const {slug} = params;
    let addresponse;
    let removeresponse;
    switch (method) {
        // 添加喜欢
        case "POST":
            addresponse = await api.favorites.addfavorites(slug);
            if (addresponse && addresponse.status !== 1) {
                throw new Error(addresponse.message)
            }
            return addresponse.data;
        // 取消喜欢
        case "DELETE":
            removeresponse = await api.favorites.removefavorites(slug);
            if (removeresponse && removeresponse.status !== 1) {
                throw new Error(removeresponse.message)
            }
            return removeresponse.data
        default:
            return new Error("请求方式错误")
    }
}